<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>登录</title>

    <script type="text/javascript" src="../static/jquery-3.2.1.min.js"></script>
</head>

    <body>
        <div >
            <div>
                <input id="userName" type="text" placeholder="用户名"/>
            </div>
            <div>
                <input id="password" type="text" placeholder="密码"/>
            </div>
            <div>
                <a id="login" href="#">登录</a>
            </div>
        </div>
    </body>

    <script>
        $("#login").click(function () {
            var userName = $("#userName").val();
            var password = $("#password").val();

            data={
                "userName": userName,
                "password": password
            }
            $.ajax({
                type: "post",
                url: "/login",
                data: data,
                dataType: "json",
                success: function (result) {
                    if("0"==result.code){
                        alert(result.message);
                    } else {
                        sessionStorage.setItem("userName",result.data.userName);
                        //将sessionid保存到sessionStorage中
                        sessionStorage.setItem("sessionId",result.message);
                        window.location.href = "/static/success.html" ;
                    }
                }

            })
        })

    </script>

</html>
